package com.orange.core.pojo.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>ClassName:PaymentStatus</p>
 * <p>Description: 支付枚举</p>
 * <p>Author: lwm</p>
 * <p>Date: 2025/7/14 15:59</p>
 */
@AllArgsConstructor
@Getter
public enum PaymentStatus implements Serializable {
    NOT_PAID(0, "未支付"),
    PAID(1, "已支付"),
    CANCELLED(2,"取消支付"),
    FAILED(3, "支付失败"),
    PENDING(4,"待支付");

    @EnumValue
    private final Integer code;

    @JsonValue
    private final String desc;

    private static final Map<String, PaymentStatus> CODE_TO_MENUM_MAP = Arrays.stream(values())
            .collect(Collectors.toUnmodifiableMap(PaymentStatus::getDesc, e -> e));

    public static PaymentStatus getByCode(String code) {
        PaymentStatus paymentStatus = CODE_TO_MENUM_MAP.get(code);
        if (paymentStatus == null) {
            throw new IllegalArgumentException("无效的code值: " + code);
        }
        return paymentStatus;
    }
}
